package com.itcanteen.medical.common.advice;

import com.itcanteen.medical.common.exception.AdException;
import com.itcanteen.medical.common.exception.PlanException;
import com.itcanteen.medical.common.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handlerException(AdException adException){
        CommonResponse  commonResponse = new CommonResponse<>(-1, "error");
        commonResponse.setData(adException.getMessage());
        return commonResponse;
    }

    @ExceptionHandler(value = PlanException.class)
    public CommonResponse<String> handlerPlanException(PlanException planException){
        CommonResponse  commonResponse = new CommonResponse<>(-1, "plan error");
        commonResponse.setData(planException.getMessage());
        return commonResponse;
    }
}
